package com.marsyang.display.ui
{
	import com.greensock.*;
	import com.greensock.easing.*;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class SuperButton extends Sprite
	{
		protected var setLabel:String = "";
		protected var setTextColorOver:uint = 0xff0000;
		protected var setTextColor:uint = 0x666666;
		protected var setColorOver:uint = 0xff0000;
		protected var setColor:uint = 0xffffff;
		protected var setName:String;
		protected var setAlpha:Number = 1;
		protected var setWidth:Number;
		protected var setHeight:Number;
		private var base:Shape;
		private var over:Shape;
		private var label:TextField;
		
		public function SuperButton(param:Object=null)
		{
			if(param!=null)
			{
				if(param.hasOwnProperty("_color")){
					this.setColor = param._color;
				}
				if(param.hasOwnProperty("_alpha")){
					this.setAlpha = param._alpha;
				}
				if(param.hasOwnProperty("_colorOver")){
					this.setColorOver = param._colorOver;
				}
				if(param.hasOwnProperty("_textColor")){
					this.setTextColor = param._textColor;
				}
				if(param.hasOwnProperty("_textColorOver")){
					this.setTextColorOver = param._textColorOver;
				}
				if(param.hasOwnProperty("_width")){
					this.setWidth = param._width;
				}
				if(param.hasOwnProperty("_height")){
					this.setHeight = param._height;
				}
			}
		}
		public function create():void {
			this.buttonMode = true;
			this.useHandCursor = true;
			
			base = new Shape();
			base.graphics.beginFill(0x000000, 0);
			base.graphics.drawRect(0, 0, setWidth, setHeight);
			addChild(base);
			
			over = new Shape()
			over.graphics.beginFill(setColor, setAlpha);
			over.graphics.drawRect(0, 0, setWidth, setHeight);;
			over.width = 0;
			addChild(over);
			
			label = new TextField();
			label.width = setWidth-5;
			label.height = setHeight;
			label.text = setLabel;
			label.textColor = setTextColor;
			label.mouseEnabled = false;
			label.autoSize = TextFieldAutoSize.RIGHT;
			label.filters = [];
			addChild(label);
			
			this.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
			this.addEventListener(MouseEvent.MOUSE_OUT, outHandler);			
		}
		private function overHandler(e:MouseEvent):void
		{
			label.textColor = setTextColorOver;
			TweenLite.to(over, 0.2, {width:setWidth});
		}
		private function outHandler(e:MouseEvent):void
		{
			label.textColor = setTextColor;
			TweenLite.to(over, 0.2, {width:0});
		}
		public override function set name(v:String):void {
			this.setName = v;
		}
		public override function get name():String {
			return setName;
		}
		public function set _alpha(v:Number):void {
			this.setAlpha = v;
		}
		public function get _alpha():Number {
			return setAlpha;
		}
		public function set _width(v:Number):void {
			this.setWidth = v;
		}
		public function get _width():Number {
			return setWidth;
		}
		public function set _height(v:Number):void {
			this.setHeight = v;
		}
		public function get _height():Number {
			return setHeight;
		}
		public function set _label(v:String):void {
			this.setLabel = v;
		}
		public function get _label():String {
			return setLabel;
		}
	}
}